import Vuex from 'vuex'
import Vue from 'vue'
import moduleProduct from './module/product'

Vue.use(Vuex)


var sto = {
    state:{
        userName: '也不是你',
        studentInfo:[
            {
                id:1,
                name:'也不是你',
                sex:1
            },
            {
                id:2,
                name:'jack',
                sex:0
            },
            {
                id:3,
                name:'以前的你',
                sex:1
            },
            {
                id:4,
                name:'是你',
                sex:0
            },
            {
                id:1,
                name:'也不是你',
                sex:1
            },
        ]
    },
    getters: {
        userNameOk: state =>{
            return '喜欢的是你'+state.userName
        },
        studentInfoMale: state =>{
            return state.studentInfo.filter(item => item.sex)
        },
        studentInfoFmale:state => {
            return state.studentInfo.filter(item => !item.sex)
        }
    },
    mutations:{
        updateUserName: (state,newUserName) => {
            state.userName = newUserName
        }
    },
    actions:{
        // getUserInfo: (ctx,token) => {
        //     // ctx.state.userName = token
        //     ctx.commit('updateUserName')
        // }
        getUserInfo: ({commit},token) => {
            // ctx.state.userName = token
            setTimeout(() => {
                console.log('2秒以后执行方法')
            },2000);
            commit('updateUserName',token)
        }
    },
    module: {
        moduleProduct
    }
}      
const store = new Vuex.Store(sto)
// const store = new Vuex.Store({
//   state: {
//     count:0,
//     todos: [
//       {id: 1,title: '55879', done: true},
//       {id: 2,title: '55879', done: false},
//       {id: 3,title: '55879', done: false},
//       {id: 4,title: '55879', done: true},
//       {id: 5,title: '55879', done: true},
//     ],
//     userInfo: {
//         id:0,
//         userName:'',
//         sex:'男',
//         avatar:'',
//         access:[]
//     }
//   },mutations:{
//     increment:function(state) {
//       state.count++
//     },
//     incrementBy: (state,num) => {
//         state.count += num
//     }
//   },
//   getters: {
//     todoDone: state => {
//       return state.todos.filter(item=>item.done === true)
//     },
//     todoDoneCount: (state,getters)=>{
//       return getters.todoDone.length
//     }
//   }
// })

store.commit('updateUserName','曾经')

export default store